package com.fanhao.dllo.soundfm.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fanhao.dllo.soundfm.R;
import com.fanhao.dllo.soundfm.entity.InforSubTypeResult;
import com.fanhao.dllo.soundfm.utils.Circlelmage;
import com.fanhao.dllo.soundfm.utils.CountToOthers;
import com.fanhao.dllo.soundfm.volley.GetBitmap;

import java.util.List;

/**
 * Created by dllo on 16/1/19.
 */
public class InforTwoAdapter extends BaseAdapter {
    private Context context;
    private List<InforSubTypeResult.ListEntity> list;

    public InforTwoAdapter(Context context) {
        this.context = context;
    }

    // 获得集合
    public void addInforSubTypeData(List<InforSubTypeResult.ListEntity> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list != null && list.size() > 0 ?
                list.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (list != null && list.size() > 0) {
            InforTwoViewHolder inforHodler = null;
            if (convertView == null) {
               convertView= LayoutInflater.from(context)
                        .inflate(R.layout.fragment_inforstypetwo_adapter_item, parent, false);
                inforHodler = new InforTwoViewHolder(convertView);
                convertView.setTag(inforHodler);
            } else {
                inforHodler = (InforTwoViewHolder) convertView.getTag();
            }
            inforHodler.titleInforTwoTv.setText(list.get(position).getTitle());
                inforHodler.anchorInforTwoTv.setText("by "+list.get(position).getNickname());

            inforHodler.playCountsInforTwoTv.setText(
                    CountToOthers.getCountToWan(list.get(position).getPlaysCounts()));
            inforHodler.timeInforTwoTv.setText(
                    CountToOthers.getCountToHour(list.get(position).getDuration()));
            inforHodler.likesInforTwoTv.setText(list.get(position).getFavorivtesCounts() + "");
            inforHodler.commentsInforTwoTv.setText(list.get(position).getCommentsCounts() + "");
            GetBitmap.getBitmap(list.get(position).getCoverSmall(),inforHodler.inforTwoIv);
        }
        return convertView;
    }

    class InforTwoViewHolder {
        TextView titleInforTwoTv, anchorInforTwoTv, playCountsInforTwoTv,
                likesInforTwoTv, timeInforTwoTv, commentsInforTwoTv;
        Circlelmage inforTwoIv;

        public InforTwoViewHolder(View view) {
            titleInforTwoTv = (TextView) view.findViewById(R.id.tvSubTitle_inforTwoAdapter);
            Log.d("InforTwoViewHolder", "lalal");
            anchorInforTwoTv = (TextView) view.findViewById(R.id.tvDescrip_inforTwoAdapter);
            playCountsInforTwoTv = (TextView) view.findViewById(R.id.tvPlayCounts_inforTwoAdapter);
            timeInforTwoTv = (TextView) view.findViewById(R.id.tvTime_inforTwoAdapter);
            likesInforTwoTv = (TextView) view.findViewById(R.id.tvLikes_inforTwoAdapter);
            commentsInforTwoTv = (TextView) view.findViewById(R.id.tvComments_inforTwoAdapter);
            inforTwoIv = (Circlelmage) view.findViewById(R.id.iv_inforTwoAdapter);
        }
    }
}
